﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace MultipleBooking
{
    public static class Dialogs
    {
        public static DialogResult InputBox(string title, out List<string> result, params string[] args)
        {
            Form form = new Form();
            List<Label> labels = new List<Label>();
            List<TextBox> textboxes = new List<TextBox>();
            Button buttonOk = new Button();
            Button buttonCancel = new Button();

            FlowLayoutPanel flpl = new FlowLayoutPanel() { Left = 0, FlowDirection = FlowDirection.TopDown, Width=150 };
            FlowLayoutPanel flpt = new FlowLayoutPanel() { Left = 150, FlowDirection = FlowDirection.TopDown };

            form.Text = title;
            foreach (var q in args)
            {
                Label l = new Label() { Text = q, AutoSize = true, Font = new Font("Verdana", 12.0f) };
                TextBox t = new TextBox() { Anchor = AnchorStyles.Right };
                labels.Add(l);
                textboxes.Add(t);
                flpl.Controls.Add(l);
                flpt.Controls.Add(t);
            }
            

            buttonOk.Text = "OK";
            buttonCancel.Text = "Cancel";
            buttonOk.DialogResult = DialogResult.OK;
            buttonCancel.DialogResult = DialogResult.Cancel;

            
            buttonOk.SetBounds(228, 72, 75, 23);
            buttonCancel.SetBounds(309, 72, 75, 23);

            buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
            buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;

            flpl.Controls.Add(buttonOk);
            flpt.Controls.Add(buttonCancel);

            form.ClientSize = new Size(396, 107);
            form.Controls.AddRange(new Control[] { flpl, flpt });
            form.ClientSize = new Size(Math.Max(300, textboxes.Count * 40 + 10), form.ClientSize.Height);
            flpl.Height = flpt.Height = form.Height = textboxes.Count * 40 + 40;
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.MinimizeBox = false;
            form.MaximizeBox = false;
            form.AcceptButton = buttonOk;
            form.CancelButton = buttonCancel;

            DialogResult dialogResult = form.ShowDialog();
            result = new List<string>();
            foreach (var t in textboxes)
            {
                result.Add(t.Text);
            }
            return dialogResult;
        }
    }
}
